package br.com.registrofinancas.adapters;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import br.com.registrofinancas.R;

/**
 * Adapter utilizado para exibição dos dados de movimentação dos itens
 * apresentados na lista de um Category. Adapter para as linhas de um Category
 */
public class CategoryMovimentationItemRowAdapter extends ArrayAdapter<Object> {

	Context context;
	int layoutResourceId;
	Object data[] = null;

	/**
	 * Construtor.
	 * 
	 * @param context
	 *            O Context.
	 * @param resource
	 *            O
	 * @param objects
	 */
	public CategoryMovimentationItemRowAdapter(Context context,
			int layoutResourceId, Object[] data) {
		super(context, layoutResourceId, data);
		this.layoutResourceId = layoutResourceId;
		this.context = context;
		this.data = data;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		/*
		 * The convertView argument is essentially a "ScrapView" as described is
		 * Lucas post
		 * http://lucasr.org/2012/04/05/performance-tips-for-androids-listview/
		 * It will have a non-null value when ListView is asking you recycle the
		 * row layout. So, when convertView is not null, you should simply
		 * update its contents instead of inflating a new row layout.
		 */
		if (convertView == null) {
			// inflate the layout
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			convertView = inflater.inflate(layoutResourceId, parent, false);
		}

		// object item based on the position
		Object objectItem = data[position];

		// get the TextView and then set the text (item name) and tag (item ID)
		// values
		
		ImageView rowIcon = (ImageView) convertView.findViewById(R.id.activity_category_expense_rowlayout_icon);
		// TODO: setIcon conforme lógica ...
		
		TextView textViewItem = (TextView) convertView.findViewById(R.id.activity_category_expense_rowlayout_label);
		textViewItem.setText("Este item aparecerá na lista" /* objectItem.toString() */);
//		textViewItem.setTag(objectItem.itemId);

		return convertView;
	}
	
}
